package org.ajiaojr.enigmagm.db;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnectionManager {
	private static ConnectionManager instance;

	private DataSource pool;

	private ConnectionManager() throws NamingException {
		pool = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/enigma");
	}

	public Connection getConnection() throws SQLException {
		return pool.getConnection();
	}

	public static synchronized ConnectionManager getInstance()
			throws NamingException {
		if (instance == null) {
			instance = new ConnectionManager();
		}
		return instance;
	}
}
